#include <stdio.h>
#include <omp.h>
//编译指令
//gcc -std=c99 -fopenmp 4ReductionExample.c -o cmake-build/4ReductionExample && export OMP_NUM_THREADS=512 && time ./cmake-build/4ReductionExample
int main()
{
    int a=0;
#pragma omp parallel for num_threads(10) shared(a) default(none)
    for(int i=1;i<101;i++)
        a=a+i;
    printf("a1=%d\n",a);
    
    a=0;
#pragma omp parallel for num_threads(10) reduction(+:a)  default(none)
    for(int i=1;i<101;i++)
        a=a+i;
    printf("a2=%d\n",a);
    
    
    
    a=0;
    for(int i=1;i<101;i++)
        a=a+i;
    printf("a3=%d\n",a);
    
    a=0;
    #pragma omp parallel for num_threads(10) reduction(-:a)  default(none)
    for(int i=1;i<101;i++)
        a=a-i;
    printf("a3=%d\n",a);
    
    
    return 0;
}

